#include "Observable.h"
#include "Observer.h"

#include <algorithm>

typedef std::vector<Observer*> obs_vec;

void Observable::attach(Observer *o)
{
	_observers.push_back(o);
}

void Observable::unattach(Observer *o)
{
	// probably will only erase one, but maybe more
	_observers.erase(
			remove(_observers.begin(), _observers.end(), o),
			_observers.end());
}

void Observable::notifyObservers()
{
	for (obs_vec::iterator iter = _observers.begin(); iter != _observers.end();
			++iter)
		(*iter)->update(this);
}

